<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
       function  exportTable() {
          const labelList = [
            //    {label:'序号',value:'index' },
            { label: "环保号码", value: "mechtype" },
            { label: "机械名称", value: "mechname" },
            { label: "机械类别", value: "mechType" },
            { label: "燃料类型", value: "rllx" },
            { label: "申报状态", value: "scrapStatusName" },
          ];
          this.getHTML(this.batchList, labelList);
        }
        // 获取html
        function   getHTML(data, column) {
          let tableStr = `<table style="vnd.ms-excel.numberformat:@"><thead><tr>`;
          column.forEach((item) => {
            tableStr += `<th>${item.label}</th>`;
          });
          tableStr += `</tr></thead><tbody>`;
          data.forEach((item) => {
            tableStr += "<tr>";
            labelList.forEach((i) => {
              tableStr += ` <td>${item[i.value]}</td>`;
            });
            tableStr += "</tr>";
          });
          tableStr += "</tbody></table>";
          console.log(tableStr,'tableStr');
          
          var uri = "data:application/vnd.ms-excel;base64,";
          var template =
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"' +
            'xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>' +
            "<x:Name>Sheet1</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets>" +
            "</x:ExcelWorkbook></xml><![endif]-->" +
            "</head><body>" +
            tableStr +
            "</body></html>";
          var a = document.createElement("a");
          a.href = uri + window.btoa(unescape(encodeURIComponent(template)));
          a.download = `报废列表.xls`;
          a.target = "";
          document.body.appendChild(a).click();
          document.body.removeChild(a);
        }
    </script>
</body>
</html>